<template>
  <div>
    <a-select @change="handleChange" v-model="innerValue" placeholder="请选择品牌">
      <a-select-option :value="item.id" v-for="item in brandList" :key="item.id">
        {{ item.name }}
      </a-select-option>
    </a-select>
  </div>
</template>
<script>
import { getAction } from '../../api/manage'

export default {
  props: {
    value: {
      type: String,
      require: false
    }
  },
  watch: {
    value(newVal) {
      this.innerValue = newVal
    }
  },
  created() {
    this.initBrandList()
  },
  data() {
    return {
      innerValue: undefined,
      brandList: [],
      url: {
        initBrandList: '/product/brand/list'
      }
    }
  },
  methods: {
    /**
     * 初始化品牌
     */
    initBrandList() {
      getAction(this.url.initBrandList, { pageNo: 1, pageSize: 10000 }).then(res => {
        this.brandList = res.result.records
      })
    },
    /**
     * 选择品牌
     * @param value
     */
    handleChange(value) {
      this.$emit('input', value)
    }
  }
}
</script>
